package servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utils.MysqlDBConexion;

@WebServlet("/Eliminar")
public class Eliminar extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
    public Eliminar() {
        super();
      
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		String nombre = req.getParameter("nombre");
		String apellido = req.getParameter("apellido");		
		try {
		Connection cn=MysqlDBConexion.getConexion();
		String sql="delete from tb_alumno where nombre=? and apellido=?";
		PreparedStatement pst=cn.prepareStatement(sql);
		pst.setString(1, nombre);
		pst.setString(2, apellido);	
		pst.executeUpdate(); 		
		RequestDispatcher rd = req.getRequestDispatcher("Logeo.jsp");
		req.setAttribute("msg", "Alumno eliminado exitosamente!");
		rd.forward(req, res);		
		} catch (Exception e) {
			e.printStackTrace();
		}			
	}

}
